using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;

public class WindManager_Tutorial : MonoBehaviour
{
    public float WindValueOffset = 1;
    public float WindMaxMagnitude = 3;
    public float UpdateWindTime = .5f;
    public float StartWindValueMagnitude = 3;
    [SerializeField]private Vector2 WindValue;
    private Vector2 updateWindValue;
    private float time;

    public Vector3 GetWindValue=> new Vector3(WindValue.x,0,WindValue.y);
    
    private Vector2 GenerateWind()
    {
        var tmp_RandomWindVector = WindValue + Random.insideUnitCircle * WindValueOffset;
        return tmp_RandomWindVector.normalized * Mathf.Min(tmp_RandomWindVector.magnitude, WindMaxMagnitude);
    }

    private void Start()
    {
        time = 0;
        WindValue = Random.insideUnitCircle * StartWindValueMagnitude;
        updateWindValue = WindValue;
    }

    private void Update()
    {
        UpdateWind();
        time += Time.deltaTime;
        if (time > UpdateWindTime)
        {
            time = 0;
            updateWindValue = GenerateWind();
        }
    }

    private void UpdateWind()
    {
        WindValue = Vector2.Lerp(WindValue, updateWindValue, Time.deltaTime);
    }
}